<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增设备管理')" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="white-bg" ng-app="ia" ng-controller="addDeviceController" ng-init="getDeviceTypeList()">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-device-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">所属项目：</label>
                <div class="col-sm-8">
                   <!-- <select name="projectId" class="form-control m-b" ng-model="projectId" ng-options="project.projectId as project.projectName for project in projectList"  required>
                        <option value="">请选择一个设备类型</option>
                        <option ng-repeat="com in coms" value="{{com.name}}">{{com.name}}</option>
                    </select>-->
                    <select name="projectId" class="form-control m-b" required>
                        <option value="">请选择一个设备类型</option>
                        <option ng-repeat="project in projectList" value="{{project.projectId}}">{{project.projectName}}</option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">设备SN码：</label>
                <div class="col-sm-8">
                    <input name="deviceSn" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">设备名称：</label>
                <div class="col-sm-8">
                    <input name="deviceName" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">设备类型：</label>
                <div class="col-sm-8">
                    <select name="deviceType" class="form-control m-b" th:with="type=${@dict.getType('IOT_DEVICE_TYPE')}" required>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">设备位置：</label>
                <div class="col-sm-8">
                    <input name="devicePosition" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">设备图片：</label>
                <div class="col-sm-8">
                    <input type="hidden" name="deviceImg">
                    <div class="file-loading">
                        <input class="form-control file-upload" id="deviceImg" name="file" type="file">
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">设备描述：</label>
                <div class="col-sm-8">
                    <input name="deviceDescription" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">设备软件版本号：</label>
                <div class="col-sm-8">
                    <input name="deviceSoftversion" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">设备阈值_最小值：</label>
                <div class="col-sm-8">
                    <input name="deviceThresholdmin" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">设备阈值_最大值：</label>
                <div class="col-sm-8">
                    <input name="deviceThresholdmax" class="form-control" type="text">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-fileinput-js"/>
    <script th:inline="javascript">
        var prefix = ctx + "iot/device"
        $("#form-device-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-device-add').serialize());
            }
        }

        $(".file-upload").fileinput({
            uploadUrl: ctx + 'common/upload',
            maxFileCount: 1,
            autoReplace: true
        }).on('fileuploaded', function (event, data, previewId, index) {
            $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
        }).on('fileremoved', function (event, id, index) {
            $("input[name='" + event.currentTarget.id + "']").val('')
        })
    </script>

    <script  type="text/javascript">
        var app=angular.module('ia',[]);
        app.controller('addDeviceController',function ($scope,$http) {

            //获取设备类型列表,获取用户列表,获取农场列表
            $scope.getDeviceTypeList=function () {
                $http.get('/iot/device/getAllProjectList').then(function (response) {
                    //$scope.deviceTypeList=response.data.deviceTypeList;
                    $scope.projectList=response.data.projectList;
                    console.log($scope.projectList);
                    //$scope.userList=response.data.userList;
                });
            }
        });
    </script>
</body>
</html>